#include<allegro.h>
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include"background.h"
#include"struct.h"
#include"sound.h"
#define GFX_W 800
#define GFX_H 600



int main()
{
jimmy jim;
personnage pers;
SAMPLE *intro;
SAMPLE *sound;
SAMPLE *anim;



BITMAP *Buffer;
	BITMAP *background1;
BITMAP *Background2;
BITMAP *Background3;
BITMAP *Background4;
BITMAP *Background5;
BITMAP *Background6;
BITMAP *Image;
BITMAP *menu;
BITMAP *menu2;
BITMAP *aide;
BITMAP *acceuil;
BITMAP *taj;
BITMAP *pyra;
BITMAP *chich;
BITMAP *mur;
BITMAP *stat;
BITMAP *tour;
int i;

allegro_init();
	if (install_keyboard() == -1) {
		allegro_message("Error! %s", allegro_error);
		return (-1);
	}
	set_color_depth(24);
	if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, GFX_W, GFX_H, 0, 0) != 0) {
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); 
		allegro_message("Unable to initialize video mode!\n%s\n", allegro_error);
		return (1);
	}


if(install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL)) {
  allegro_message("Sound Error: %s", allegro_error);
  
}
intro = load_sample("intro.wav");
anim = load_sample("intro.wav");
Buffer = create_bitmap(800,600);
background1=load_bitmap("../images/background1.bmp",NULL);
Background2=load_bitmap("../images/background2.bmp",NULL);
Background3=load_bitmap("../images/background3.bmp",NULL);
Background4=load_bitmap("../images/background4.bmp",NULL);
Background5=load_bitmap("../images/background5.bmp",NULL);
Background6=load_bitmap("../images/background6.bmp",NULL);
menu=load_bitmap("../images/menu.bmp",NULL);
menu2=load_bitmap("../images/menu2.bmp",NULL);
aide=load_bitmap("../images/aide.bmp",NULL);
acceuil=load_bitmap("../images/acceuil.bmp",NULL);
taj=load_bitmap("../images/mm.bmp",NULL);
pyra=load_bitmap("../images/p.bmp",NULL);
chich=load_bitmap("../images/c.bmp",NULL);
mur=load_bitmap("../images/m.bmp",NULL);
tour=load_bitmap("../images/t.bmp",NULL);
stat=load_bitmap("../images/l.bmp",NULL);

/*jim.img_right[0] = load_bitmap("../images/right0.bmp", NULL);
jim.img_right[1] = load_bitmap("../images/right1.bmp", NULL);
jim.img_right[2] = load_bitmap("../images/right2.bmp", NULL);
jim.img_left[0] = load_bitmap("../images/left0.bmp", NULL);
jim.img_left[1] = load_bitmap("../images/left1.bmp", NULL);
jim.img_left[2] = load_bitmap("../images/left2.bmp", NULL);
Image=load_bitmap("./images/left0.bmp",NULL);*/

/*load_jimmy(&jim);
init_jimmy(&jim);*/
/*for(i=0;i<3;i++)
{
if(Background1==NULL &&jim.img_left[i]==NULL && jim.img_right[i])
{
	allegro_message("could not load images");
	allegro_exit();
}
}

jim.x=SCREEN_W/2;
jim.y=(4*SCREEN_H)/5;*/
	
son_fort(intro);
 load_jimmy(&jim);
     init_jimmy(&jim);


while(!keypressed())
{

blit(acceuil,Buffer,0,0,0,0,GFX_W,GFX_H);
blit(Buffer,screen,0,0,0,0,GFX_W,GFX_H);
   

/*textprintf_centre_ex(screen, font, SCREEN_W / 2, SCREEN_H/2,
makecol(0, 100, 243), -1,
"Bienvenue!");*/



}

while (!key[KEY_Q])
{ /*load menu*/

blit(menu,Buffer,0,0,0,0,GFX_W,GFX_H);
blit(Buffer,screen,0,0,0,0,GFX_W,GFX_H);
   
    if(key[KEY_1]){

break;}
   /*   if(key[KEY_P])
              {break;}
       if(key[KEY_M])
           {break;}
        if(key[KEY_L]) {break;}
          if(key[KEY_C]) {break;}
              if(key[KEY_E]) {break;}
                if(key[KEY_T]) {break;}
                     if(key[KEY_R]) {break;}*/
                   
           



         
        if(key[KEY_2]) {break;}
        if(key[KEY_3]) {break;}
       if(key[KEY_4]) {break;}

}
            /* { 
blit(niveaux,Buffer,0,0,0,0,GFX_W,GFX_H);
blit(Buffer,screen,0,0,0,0,GFX_W,GFX_H); 

              if(key[KEY_P])*/
while(1)
{blit(menu2,Buffer,0,0,0,0,GFX_W,GFX_H);
blit(Buffer,screen,0,0,0,0,GFX_W,GFX_H);
if(key[KEY_P])
              {break;}
       if(key[KEY_M])
           {break;}
        if(key[KEY_L]) {break;}
          if(key[KEY_C]) {break;}
              if(key[KEY_E]) {break;}
                if(key[KEY_T]) {break;}
                     if(key[KEY_R]) {break;}
                   

}
  while(key[KEY_P]){
     clear_bitmap(Buffer);
     son_bas(anim);
      Buffer =create_bitmap(800,600);
      blit(pyra,Buffer,0,0,0,0,GFX_W,GFX_H);
      blit(Buffer,screen,0,0,0,0,GFX_W,GFX_H);
    sleep(8);
    clear_bitmap(Buffer);
   
//blit(Background1,Buffer,0,0,0,0,800,600);
//blit(Buffer,screen,0,0,0,0,GFX_W,GFX_H);
/*** Loading Background ****/
//blit(background1,Buffer,0,0,0,0,background1->w,background1->h);
//blit(Buffer,screen,0,0,0,0,GFX_W,GFX_H);
  move(&jim,background1);
 blit(background1,Buffer,0,0,0,0,SCREEN_W,SCREEN_H);
draw_jimmy(jim,Buffer);
blit(Buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H);

 


//draw_sprite(Buffer,Image,SCREEN_W/2,(4*SCREEN_H)/5);
//blit(Buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H);

//load_jimmy(&jim);
	
//init_jimmy(&jim);

//deplacergauche_jimmy(&jim);
//deplacerdroite_jimmy(&jim,Background1);


              }
    /*   if(key[KEY_T])
{Buffer =create_bitmap(800,600);
blit(Background2,Buffer,0,0,0,0,800,600);
blit(Buffer,screen,0,0,0,0,GFX_W,GFX_H);*/


    /* if(key[KEY_2])
           { sauvegarde du jeu commencer auparavant}
        
      if(key[KEY_3])

     {if (key[KEY_O])
           { play son}
         if (key[KEY_M])
            {stop son}
     }   
*/
  

         //if(key[KEY_4]){break;}
while(4)
            {/*destroy_bitmap(screen);*/

Buffer =create_bitmap(800,600);
 blit(aide,Buffer,0,0,0,0,GFX_W,GFX_H);
                 blit(Buffer,screen,0,0,0,0,GFX_W,GFX_H);
                }





/*blit(menu, Buffer, 0, 0, 0, 0, 800, 680);
blit( Buffer,screen, 0, 0, 0, 0, 800, 680);*/

/*
}*/

/*while (key[KEY_ENTER])
{*/


/*blit(Background1,Buffer,0,0,0,0,Background1->w,Background1->h);
blit(Buffer,screen,0,0,0,0,GFX_W,GFX_H);
load_jimmy(&jim);

	
init_jimmy(&jim);*/
/*deplacergauche_jimmy(&jim);
deplacerdroite_jimmy(&jim);
}*/


return 0;
}

END_OF_MAIN();




